#!/bin/sh

# The first argument is the number of packages left after
# this one has been removed. If it is 0 then the package is being
# removed from the system.
if [ "$1" = "0" ] || [ "$1" = "remove" ]
then
    if [ -f /etc/ld.so.conf.d/maxscale.conf ]
    then
        rm /etc/ld.so.conf.d/maxscale.conf
    fi

    if [ -f /usr/lib/systemd/system/maxscale.service ]
    then
        systemctl stop maxscale.service > /dev/null
        systemctl disable maxscale.service > /dev/null 2>&1
        rm /usr/lib/systemd/system/maxscale.service
        systemctl daemon-reload > /dev/null
    elif [ -f /lib/systemd/system/maxscale.service ]
    then
        systemctl stop maxscale.service > /dev/null
        systemctl disable maxscale.service > /dev/null  2>&1
        rm /lib/systemd/system/maxscale.service
        systemctl daemon-reload > /dev/null
    fi

    if [ -f /etc/logrotate.d/maxscale_logrotate ]
    then
        rm /etc/logrotate.d/maxscale_logrotate
    fi
fi
